package com.eb.controller;


import com.eb.dto.PreservePageQueryDTO;
import com.eb.result.PageResult;
import com.eb.result.Result;
import com.eb.service.PreserveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/preserve")
@Api(tags = "收藏接口")
@Slf4j
@CrossOrigin
public class PreserveController {

    @Autowired
    private PreserveService preserveService;
    /**
     * 新建收藏
     * @param id
     * @return
     */
    @PostMapping("/add/{id}")
    @ApiOperation("新建收藏")
    public Result addPreserve(@PathVariable Integer id){
        log.info("新建收藏: {}", id);
        preserveService.addPreserve(id);
        return Result.success();
    }

    /**
     * 取消收藏
     * @param innovationId
     * @return
     */
    @DeleteMapping("/delete")
    @ApiOperation("取消收藏")
    public Result cancerPreserve(Integer innovationId){
        log.info("取消收藏: {}", innovationId);
        preserveService.deletePreserve(innovationId);
        return Result.success();
    }

    /**
     * 分页查询收藏
     * @param preservePageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("分页查询收藏")
    public Result<PageResult> page(PreservePageQueryDTO preservePageQueryDTO){
        log.info("分页查询收藏: {}", preservePageQueryDTO);
        PageResult pageResult = preserveService.pageQuery(preservePageQueryDTO);
        return Result.success(pageResult);
    }
}
